/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package view.GUI.actions;

import controller.commands.ExecuteCommand;
import core.Tracker;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import model.graphic.GraphicModel;
import view.GUI.LabelReader;
import view.GUI.graphic.GraphicView;

/**
 *
 * @author Arfeniel
 */
public class RunAction extends AbstractAction{
    private GraphicModel gmodel;
    private GraphicView gview;

 

    public RunAction(GraphicView gview, GraphicModel gmodel) {
        this.gview = gview;
        this.gmodel=gmodel;
    }

    public void actionPerformed(ActionEvent e) {
        if(gmodel.isMainTriggerSet()){
            controller.StdDraw.getInstance().getTurtle().reset();//reset the turtle to its start position
            Tracker.setInstance(new Tracker());
            gview.notifyObservers(new ExecuteCommand(gmodel.getMainTrigger()));
        }else{
            JOptionPane.showMessageDialog(gview.getParent(), LabelReader.getInstance().getString("SetMainTriggerError"), LabelReader.getInstance().getString("Error"),JOptionPane.INFORMATION_MESSAGE);
        }
    }

}
